<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$this->model('model')->checkjuese(14);
$juese_id=14;
$workerids=$this->model('model')->getworkerids($juese_id);
if($_RQ['op']=='list'){
	$return['params']=array();
	$params=$params2=array('uniacid'=>$_SESSION['uniacid']);
	if($_SESSION['storeids']){
		$params['storeid']=$_SESSION['storeids'];
	}
	if($_RQ['storeid']){
		$params['storeid']=$_RQ['storeid'];
		$params2['storeid']=$_RQ['storeid'];
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if($_RQ['type']){
		$params['type']=intval($_RQ['type']);
		$return['params']['type']=$_RQ['type'];
	}
	if($_RQ['worker5id']){
		$params['worker5id']=intval($_RQ['worker5id']);
		$return['params']['worker5id']=$_RQ['worker5id'];
	}
	if($_RQ['worker6id']){
		$params['worker6id']=intval($_RQ['worker6id']);
		$return['params']['worker6id']=$_RQ['worker6id'];
	}
	$params['status']=intval($_RQ['status']);
	$return['params']['status']=intval($_RQ['status']);
	if($_RQ['title']){
		$params2['title like']='%'.trim($_RQ['title']).'%';
		$memberids=pdo_getall('jy_yxw_member',$params2,'id','id');
		if($memberids){
			$memberids=array_keys($memberids);
		}else{
			$memberids=-1;
		}
		$params['memberid']=$memberids;
		$return['params']['title']=$_RQ['title'];
	}
	if($_RQ['mobile']){
		$params2['mobile like']='%'.trim($_RQ['mobile']).'%';
		$memberids=pdo_getall('jy_yxw_member',$params2,'id','id');
		if($memberids){
			$memberids=array_keys($memberids);
		}else{
			$memberids=-1;
		}
		$params['memberid']=$memberids;
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['createtime']=$time_range;
		$params['tuidaytime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:50;
	if($_RQ['psize']){
		$return['params']['psize']=$_RQ['psize'];
	}
	$list=pdo_getslice('jy_yxw_tuifee_log',$params,array($pindex,$psize),$total,$fields,'','tuidaytime desc,id desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['member']=$this->model('member')->member_show($item['memberid']);
			$item['type']=$item['type']?:1;
			if($item['status']==4){
				if($item['type']==2){
					//pdo_update('jy_yxw_infee_log',array('type'=>5,'status'=>4),array('status'=>array(1,4),'type'=>2,'uniacid'=>$_SESSION['uniacid'],'memberid'=>$item['memberid']));
				}elseif($item['type']==1 || !$item['type']){
					//pdo_update('jy_yxw_infee_log',array('type'=>4,'status'=>4),array('status'=>array(1,4),'type'=>1,'uniacid'=>$_SESSION['uniacid'],'memberid'=>$item['memberid']));
				}
			}
			if(!$item['tuidaytime'] && $item['tuiday']){
				pdo_update('jy_yxw_tuifee_log',array('tuidaytime'=>strtotime($item['tuiday'])),array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['id']));
			}
			if(!$item['worker5id'] && !$item['worker6id'] && !$item['workerheid']){
				$member=pdo_get('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['memberid']),array('worker5id','worker6id','workerheid','from1_type','from2_type'));
				$update=array(
					'worker5id'=>$member['worker5id'],
					'worker6id'=>$member['worker6id'],
					'workerheid'=>$member['workerheid'],
					'from1_type'=>$member['from1_type'],
					'from2_type'=>$member['from2_type'],
				);
				pdo_update('jy_yxw_tuifee_log',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['id']));
			}
			$member=pdo_get('jy_yxw_member',array('id'=>$item['memberid'],'uniacid'=>$_SESSION['uniacid']),array('title','cardno','worker5id','worker6id'));
			$item['worker6title']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$member['worker6id']),'title');
			$item['worker5title']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$member['worker5id']),'title');
			if($item['status']==4){
				$isfeelog=pdo_get('jy_yxw_feelog',array('tuifeeid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
				if(!$isfeelog['id']){
					$this->model('feelog')->upfeelog($item['id'],'',$item['type']==2?4:3);
				}elseif(!$isfeelog['status']){
					pdo_update('jy_yxw_feelog',array('status'=>1),array('tuifeeid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
				}
			}
			if(!$item['shoustoreid']){
				$item['shoustoreid']=pdo_getcolumn('jy_yxw_yonghu',array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$item['memberid']),'storeid');
				if($item['shoustoreid']){
					pdo_update('jy_yxw_tuifee_log',array('shoustoreid'=>$item['shoustoreid']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['id']));
				}
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'已收取金额-退费金额=门店收益','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'storeid','title'=>'所属门店','type'=>'select2','options'=>'stores'),
			array('name'=>'member','title'=>'客户信息','type'=>'member'),
			array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'type'),
			array('type'=>'unitstring','unit'=>'元','title'=>'已交金额','name'=>'fee'),
			array('type'=>'unitstring','unit'=>'元','title'=>'退款收费','name'=>'isfee'),
			array('type'=>'string','title'=>'退款收费账户','name'=>'inzhanghu'),
			array('type'=>'string','title'=>'退款收费日期','name'=>'inday'),
			array('name'=>'infee1','title'=>'总部退款收费分摊','type'=>'unitstring','unit'=>'元'),
			array('name'=>'infee2','title'=>'售后基地退款收费分摊','type'=>'unitstring','unit'=>'元'),
			array('name'=>'infee3','title'=>'销售门店退款收费分摊','type'=>'unitstring','unit'=>'元'),
			array('name'=>'remark','title'=>'退费原因','type'=>'string'),
			array('type'=>'string','title'=>'实际退费金额','name'=>'tuifee'),
			array('type'=>'string','title'=>'退费账户','name'=>'zhanghu'),
			array('type'=>'string','title'=>'退费日期','name'=>'tuiday'),
			array('name'=>'fee1','title'=>'总部退费分摊','type'=>'unitstring','unit'=>'元'),
			array('name'=>'fee2','title'=>'售后基地退费分摊','type'=>'unitstring','unit'=>'元'),
			array('name'=>'fee3','title'=>'销售门店退费分摊','type'=>'unitstring','unit'=>'元'),
			array('name'=>'worker6title','title'=>'销售员','type'=>'string'),
			array('name'=>'worker5title','title'=>'电客','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		),'action'=>array(
			array('type'=>'modal','action'=>'/juese14.tuifee/look/','title'=>'查看详情'),
			array('type'=>'href','action'=>'/juese14.tuifee/check/','title'=>'审批','show'=>array('status'=>1)),
			array('type'=>'href','action'=>'/juese14.tuifee/check2/','title'=>'修改','show'=>array('status'=>4)),
		)),
		'search'=>array(
			array('name'=>'storeid','width'=>10,'title'=>'所属门店','type'=>'select','options'=>'stores'),
			array('name'=>'title','width'=>10,'title'=>'姓名','type'=>'string'),
			array('name'=>'mobile','width'=>10,'title'=>'电话','type'=>'string'),
			array('title'=>'电客员','width'=>'10','name'=>'worker5id','type'=>'select','options'=>'workers5'),
			array('title'=>'销售员','width'=>'10','name'=>'worker6id','type'=>'select','options'=>'workers6'),
			array('name'=>'type','width'=>'10','title'=>'类型','type'=>'radio','options'=>'type'),
			array('name'=>'createtime','width'=>15,'title'=>'申请时间','type'=>'time_range'),
		),
	);
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_SESSION['storeids']){
		$params['id']=$_SESSION['storeids'];
	}
	$return['workers5']=$this->getall('worker',array('juese'=>5,'uniacid'=>$_SESSION['uniacid'],'status'=>1),array('id','title'),'id');
	$return['workers6']=$this->getall('worker',array('juese'=>6,'uniacid'=>$_SESSION['uniacid'],'status'=>1),array('id','title'),'id');
	$return['stores']=$this->getall('store',$params,array('id','title'),'id');
	$return['type']=array(1=>'退成交',2=>'退定金');
	$return['status']=$this->tuifee_status;
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='look'){
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_tuifee_log',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	}else{
		exi('请先选择客户','error');
	}
	$return['item']=$item;	
	$htmls=array(
		'type'=>'look',
	);
	$htmls['look']=array(
		array('type'=>'tip','title'=>'发起“退成交”申请，成交成功后退成交，向“店长”发起，店长确认达到“财务”系统。'),
		array('type'=>'string','title'=>'售后姓名','name'=>'title'),
		array('type'=>'string','unit'=>'元','title'=>'已交金额','name'=>'fee'),
		array('type'=>'string','unit'=>'元','title'=>'退款收费','name'=>'isfee','help'=>'退费需扣除的部分（比如已上课7天，需扣除1000），这里填1000'),
		array('type'=>'image','title'=>'退成交协议图片','name'=>'tuiimage'),
		array('type'=>'text','title'=>'退成交原因','name'=>'remark'),
		array('name'=>'tuifee','title'=>'实际退费金额','type'=>'string'),
		array('name'=>'zhanghu','title'=>'退费账户','type'=>'string'),
		array('name'=>'tuiday','title'=>'退费日期','type'=>'string'),
		array('name'=>'fee1','title'=>'总部退费分摊','type'=>'string'),
		array('name'=>'fee2','title'=>'售后基地退费分摊','type'=>'string'),
		array('name'=>'fee3','title'=>'销售门店退费分摊','type'=>'string'),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='check'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=$post['id'];
		if($post['check'] && !$post['remark14']){
			exi('请填写审核不通过的原因！','error');
		}
		if($post['isfee']>$post['fee']){
			exi('需收取金额不能大于已交金额！','error');
		}
		if($post['infeeid']){
			$infee_log=pdo_get('jy_yxw_infee_log',array('id'=>$post['infeeid'],'uniacid'=>$_SESSION['uniacid']));
			if($post['fee1']>$infee_log['zufee']){
				//exi('总部退费分摊不能大于实际缴补贴费费！','error');
			}
			if($post['fee2']>$infee_log['shouhoufee']){
				exi('售后基地退费分摊不能大于实际缴教本费！','error');
			}
			if($post['fee3']>$infee_log['fee']){
				//exi('销售门店退费分摊不能大于实际缴销售门店费！','error');
			}
		}
		$update=array(
			'fee1'=>$post['fee1'],
			'fee2'=>$post['fee2'],
			'fee3'=>$post['fee3'],
			'infee1'=>$post['infee1'],
			'infee2'=>$post['infee2'],
			'infee3'=>$post['infee3'],
			'fee'=>$post['fee'],
			'isfee'=>$post['isfee'],
			'infee'=>$post['isfee'],
			'zhanghu'=>$post['zhanghu'],
			'inzhanghu'=>$post['inzhanghu'],
			'tuifee'=>$post['tuifee']?:$post['fee1']+$post['fee2']+$post['fee3'],
			'tuiday'=>$post['tuiday'],
			'tuidaytime'=>strtotime($post['tuiday']),
			'inday'=>$post['inday'],
			'indaytime'=>strtotime($post['inday']),
			'remark1'=>trim($post['remark1']),
			'status'=>$post['check']?3:4,
		);
		pdo_update('jy_yxw_tuifee_log',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		if($post['type']==2){
			$update=array('up_time'=>time(),'status'=>$post['check']?114:115);
		}else{
			$update=array('up_time'=>time(),'status'=>$post['check']?104:105);
		}
		pdo_update('jy_yxw_member',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['memberid']));
		if($post['type']==2){
			$update=array('up_time'=>time(),'status'=>$post['check']?114:115);
		}else{
			$update=array('up_time'=>time(),'status'=>$post['check']?114:115);
		}
		pdo_update('jy_yxw_yonghu',$update,array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$post['memberid']));
		if(!$post['check']){
			if($post['type']==2){
				$infee_log=$infee_log?:pdo_get('jy_yxw_infee_log',array('status'=>1,'type'=>2,'uniacid'=>$_SESSION['uniacid'],'memberid'=>$post['memberid']));
				pdo_update('jy_yxw_infee_log',array('type'=>5,'status'=>4),array('id'=>$infee_log['id'],'uniacid'=>$_SESSION['uniacid'],'memberid'=>$post['memberid']));
			}elseif($post['type']==1){
				$infee_log=$infee_log?:pdo_get('jy_yxw_infee_log',array('status'=>1,'type'=>1,'uniacid'=>$_SESSION['uniacid'],'memberid'=>$post['memberid']));
				pdo_update('jy_yxw_infee_log',array('type'=>4,'status'=>4),array('id'=>$infee_log['id'],'uniacid'=>$_SESSION['uniacid'],'memberid'=>$post['memberid']));
			}
			$this->model('feelog')->upfeelog($id,'',$post['type']==2?4:3);
		}else{
			if($post['tuiyonghuid']){
				pdo_update('jy_yxw_yonghu_log',array('status'=>3,'remark14'=>$post['remark14']),array('id'=>$post['tuiyonghuid'],'uniacid'=>$_SESSION['uniacid']));
			}
		}
		exi('操作成功！','','jy_yxw/juese14.tuifee//status=0');
	}
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_tuifee_log',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		$item['member']=$this->model('member')->member_show($item['memberid']);
	}else{
		exi('请先选择客户','error');
	}
	$item['check']=0;
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'审核退成交',
	);
	$htmls['edit']=array(
		array('type'=>'tip','title'=>'发起“退成交”申请，成交成功后退成交，向“店长”发起，店长确认达到“财务”系统。'),
		array('type'=>'copy','title'=>'售后姓名','name'=>'member.nickname'),
		array('type'=>'unitstring','unit'=>'元','title'=>'已交金额','name'=>'fee','help'=>'即：支出退费金额（先全退费，再另外进账《退款收费》）'),
		array('type'=>'unitstring','unit'=>'元','title'=>'退款收费','name'=>'isfee','help'=>'退费时，会产生的《退款收费》进账'),
		array('type'=>'string_time','title1'=>'收取账户','name1'=>'inzhanghu','title2'=>'收取日期','name2'=>'inday','time_type'=>'day'),
		array('name'=>'infee1','title'=>'总部收取分摊','type'=>'unitstring','unit'=>'元'),
		array('name'=>'infee2','title'=>'售后基地收取分摊','type'=>'unitstring','unit'=>'元'),
		array('name'=>'infee3','title'=>'销售门店收取分摊','type'=>'unitstring','unit'=>'元'),
		array('type'=>'copy','title'=>'退成交原因','name'=>'remark'),
		array('type'=>'unitstring','unit'=>'元','title'=>'退费合计','name'=>'tuifee','help'=>'正常是退全部成交费《已交金额》，但考虑有税金波动！支出项以这里为准'),
		array('type'=>'string_time','title1'=>'退费账户','name1'=>'zhanghu','title2'=>'退费日期','name2'=>'tuiday','time_type'=>'day'),
		array('name'=>'fee1','title'=>'总部退费分摊','type'=>'unitstring','unit'=>'元'),
		array('name'=>'fee2','title'=>'售后基地退费分摊','type'=>'unitstring','unit'=>'元'),
		array('name'=>'fee3','title'=>'销售门店退费分摊','type'=>'unitstring','unit'=>'元'),
		array('type'=>'radio','title'=>'审批','name'=>'check','options'=>'check'),
		array('type'=>'text','title'=>'审核不通过原因','name'=>'remark14','show'=>array('check'=>1)),
	);
	$return['check']=array('审核通过','审核不通过');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='check2'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=$post['id'];
		if($post['isfee']>$post['fee']){
			exi('需收取金额不能大于已交金额！','error');
		}
		if($post['infeeid']){
			$infee_log=pdo_get('jy_yxw_infee_log',array('id'=>$post['infeeid'],'uniacid'=>$_SESSION['uniacid']));
			if($post['fee1']>$infee_log['zufee']){
				//exi('总部退费分摊不能大于实际缴补贴费费！','error');
			}
			if($post['fee2']>$infee_log['shouhoufee']){
				exi('售后基地退费分摊不能大于实际缴教本费！','error');
			}
			if($post['fee3']>$infee_log['fee']){
				//exi('销售门店退费分摊不能大于实际缴销售门店费！','error');
			}
		}
		$update=array(
			'fee1'=>$post['fee1'],
			'fee2'=>$post['fee2'],
			'fee3'=>$post['fee3'],
			'infee1'=>$post['infee1'],
			'infee2'=>$post['infee2'],
			'infee3'=>$post['infee3'],
			'fee'=>$post['fee'],
			'isfee'=>$post['isfee'],
			'infee'=>$post['isfee'],
			'zhanghu'=>$post['zhanghu'],
			'inzhanghu'=>$post['inzhanghu'],
			'tuifee'=>$post['tuifee']?:$post['fee1']+$post['fee2']+$post['fee3'],
			'tuiday'=>$post['tuiday'],
			'tuidaytime'=>strtotime($post['tuiday']),
			'inday'=>$post['inday'],
			'indaytime'=>strtotime($post['inday']),
			'remark1'=>trim($post['remark1']),
		);
		pdo_update('jy_yxw_tuifee_log',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		$this->model('feelog')->upfeelog($id,'',$post['type']==2?4:3);
		exi('操作成功！','','goback');
	}
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_tuifee_log',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		$item['member']=$this->model('member')->member_show($item['memberid']);
	}else{
		exi('请先选择客户','error');
	}
	$item['check']=0;
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'退成交修改',
	);
	$htmls['edit']=array(
		array('type'=>'copy','title'=>'售后姓名','name'=>'member.nickname'),
		array('type'=>'unitstring','unit'=>'元','title'=>'已交金额','name'=>'fee','help'=>'即：支出退费金额（先全退费，再另外进账《退款收费》）'),
		array('type'=>'unitstring','unit'=>'元','title'=>'退款收费','name'=>'isfee','help'=>'退费时，会产生的《退款收费》进账'),
		array('type'=>'string_time','title1'=>'收取账户','name1'=>'inzhanghu','title2'=>'收取日期','name2'=>'inday','time_type'=>'day'),
		array('name'=>'infee1','title'=>'总部收取分摊','type'=>'unitstring','unit'=>'元'),
		array('name'=>'infee2','title'=>'售后基地收取分摊','type'=>'unitstring','unit'=>'元'),
		array('name'=>'infee3','title'=>'销售门店收取分摊','type'=>'unitstring','unit'=>'元'),
		array('type'=>'copy','title'=>'退成交原因','name'=>'remark'),
		array('type'=>'unitstring','unit'=>'元','title'=>'退费合计','name'=>'tuifee','help'=>'正常是退全部成交费《已交金额》，但考虑有税金波动！支出项以这里为准'),
		array('type'=>'string_time','title1'=>'退费账户','name1'=>'zhanghu','title2'=>'退费日期','name2'=>'tuiday','time_type'=>'day'),
		array('name'=>'fee1','title'=>'总部退费分摊','type'=>'unitstring','unit'=>'元'),
		array('name'=>'fee2','title'=>'售后基地退费分摊','type'=>'unitstring','unit'=>'元'),
		array('name'=>'fee3','title'=>'销售门店退费分摊','type'=>'unitstring','unit'=>'元'),
	);
	$return['check']=array('审核通过','审核不通过');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='export'){
	$return['params']=array();
	$params=$params2=array('uniacid'=>$_SESSION['uniacid']);
	if($_SESSION['storeids']){
		$params['storeid']=$_SESSION['storeids'];
	}
	if($_RQ['storeid']){
		$params['storeid']=$_RQ['storeid'];
		$params2['storeid']=$_RQ['storeid'];
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if($_RQ['type']){
		$params['type']=intval($_RQ['type']);
		$return['params']['type']=$_RQ['type'];
	}
	if($_RQ['worker5id']){
		$params['worker5id']=intval($_RQ['worker5id']);
		$return['params']['worker5id']=$_RQ['worker5id'];
	}
	if($_RQ['worker6id']){
		$params['worker6id']=intval($_RQ['worker6id']);
		$return['params']['worker6id']=$_RQ['worker6id'];
	}
	$params['status']=intval($_RQ['status']);
	$return['params']['status']=intval($_RQ['status']);
	if($_RQ['title']){
		$params2['title like']='%'.trim($_RQ['title']).'%';
		$memberids=pdo_getall('jy_yxw_member',$params2,'id','id');
		if($memberids){
			$memberids=array_keys($memberids);
		}else{
			$memberids=-1;
		}
		$params['memberid']=$memberids;
		$return['params']['title']=$_RQ['title'];
	}
	if($_RQ['mobile']){
		$params2['mobile like']='%'.trim($_RQ['mobile']).'%';
		$memberids=pdo_getall('jy_yxw_member',$params2,'id','id');
		if($memberids){
			$memberids=array_keys($memberids);
		}else{
			$memberids=-1;
		}
		$params['memberid']=$memberids;
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['createtime']=$time_range;
		$params['tuidaytime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$list=pdo_getall('jy_yxw_tuifee_log',$params,$fields,'','tuidaytime desc,id desc');
	if($list){
		$types=array(1=>'退成交',2=>'退定金');
		foreach($list as $k=>&$item){
			$item['member']=$this->model('member')->member_show($item['memberid']);
			$item['title']=$item['member']['nickname'];
			$item['type']=$item['type']?:1;
			$item['typetitle']=$types[$item['type']];
			$item['statustitle']=$this->tuifee_status[$item['status']];
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$member=pdo_get('jy_yxw_member',array('id'=>$item['memberid'],'uniacid'=>$_SESSION['uniacid']),array('title','cardno','worker5id','worker6id'));
			$item['worker6title']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$member['worker6id']),'title');
			$item['worker5title']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$member['worker5id']),'title');
			$item['storetitle']=pdo_getcolumn('jy_yxw_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['storeid']),'title');
		}
	}
	$header=array(
		'storetitle'=>'所属门店',
		'title'=>'客户信息',
		'typetitle'=>'类型',
		'fee'=>'已交金额',
		'isfee'=>'退款收费',
		'inzhanghu'=>'退款收费账户',
		'inday'=>'退款收费日期',
		'infee1'=>'总部退款收费分摊',
		'infee2'=>'售后基地退款收费分摊',
		'infee3'=>'销售门店退款收费分摊',
		//'remark'=>'退费原因',
		'tuifee'=>'实际退费金额',
		'zhanghu'=>'退费账户',
		'tuiday'=>'退费日期',
		'fee1'=>'总部退费分摊',
		'fee2'=>'售后基地退费分摊',
		'fee3'=>'销售门店退费分摊',
		'worker6title'=>'销售员',
		'worker5title'=>'电客',
		'statustitle'=>'状态',
		'createtime'=>'时间',
	);
	model('core/tools')->export2excel($header,$list,'审批数据');
}